/*
 * Copyright (c) 2019 Nanjing Wind Information Co., Ltd. All Rights Reserved;
 * @Package wind.autotest.web
 * @version 1.0.0
 * @Date 2019年4月12日
 * @author jlliu.Farrior@wind.com.cn
 */
package wind.autotest.web;

import javax.servlet.http.HttpServletRequest;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;

import wind.autotest.pojo.TestField;
import wind.autotest.service.frontend.TestFieldService;
import wind.autotest.util.Page4Navigator;

/**
 * @Description: <类功能描述>
 * @author jlliu.Farrior@wind.com.cn
 * @Date 2019年4月12日 下午1:39:29
 * 
 */
@RestController
public class FieldListController {
	@Autowired
	private TestFieldService testFieldService;

	@GetMapping("/tables/{table_id}/fields")
    public Page4Navigator<TestField> list(
    		@PathVariable("table_id") int table_id, 
    		@RequestParam(value = "start", defaultValue = "0") int start,
    		@RequestParam(value = "size", defaultValue = "5") int size) throws Exception {
        start = start<0 ? 0:start;
        Page4Navigator<TestField> page =testFieldService.list(table_id, start, size,5);
        return page;
    }

	@PostMapping("/fields")
	public Object add(@RequestBody TestField bean) throws Exception {
		testFieldService.add(bean);
		return bean;
	}
	
	@DeleteMapping("/fields/{id}")
	public String delete(@PathVariable("id") int id, HttpServletRequest request)  throws Exception {
		testFieldService.delete(id);
		return null;
	}
	
}
